﻿using StructureMap;
using StructureMap.Configuration.DSL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LiteBlog.IoC
{
    public enum ContainerType
    {
        Default, ControllerTests, XmlLayerTests
    }
    public class IoCContainer
    {
        private static Container _container;
        
        public static void BuildContainer(ContainerType containerType)
        {
            switch(containerType)
            {
                case ContainerType.Default:
                      _container = new Container(new IoCRegistry());
                      break;
                case ContainerType.ControllerTests:
                      _container = new Container(new RegistryForControllerTests());
                      break;
                case ContainerType.XmlLayerTests:
                      _container = new Container(new RegistryForXmlLayerTests());
                      break;
            }
        }

        static IoCContainer()
        {
            _container = new Container(new IoCRegistry());
        }

        public static T Resolve<T>()
        {
            return _container.TryGetInstance<T>();
        }

        public static object Resolve(Type t)
        {
            return _container.TryGetInstance(t);
        }
    }
}
